class HumanPlayer < Player
  
  def initialize(name, board, pool, prob_hash)
    super
  end
  
  def init_hand
    @hand = Hand.new
    puts "Enter you hand and terminate with 1 char"
    while (inp = gets.split(" ")).size == 2
      d = Domino.new inp[0].to_i, inp[1].to_i
      force_draw(d)
    end
  end
  
  def force_draw d
    @pool.remove d
    @hand.add d
    @prob_hash.remove d
  end
  
  class Hand
    
    def initialize
      @dominoes = []
    end
    
    def empty?
      @dominoes.size == 0
    end
    
    def size
      @dominoes.size
    end
    
    def add(d)
      @dominoes << d
    end
    
    def dominoes
      @dominoes
    end
    
    def remove(d)
      @dominoes.delete(d)
    end
    
    def to_s
      @dominoes.to_s
    end
    
    def dup
      h = Hand.new
      dup_doms = @dominoes.inject([]){|memo, t| memo << t.dup; memo}
      h.send(:set_dominoes, dup_doms)
      h
    end
    
    private
    
    def set_dominoes(d)
      @dominoes = d
    end
    
  end
  
  #Consider removing links to these objects and moving dependent functions to dominoes game functions module
  def dup(board, pool, prob_hash)
    p = HumanPlayer.new @name.dup, board, pool, prob_hash
    h = @hand.dup
    p.send(:set_hand, h, @points)
    p
  end
  
  private
  
  def set_hand(h, p)
    @hand = h
    @points = p
  end
  
end